<!DOCTYPE html>
<html lang="en" xmlns:templet="http://www.w3.org/1999/xhtml" xmlns:margin-left="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>腾飞健康管理平台</title>
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <style>
        .word {
            position: absolute;
            right: 10px;
            bottom: 10px;
            color: #aaa;
            font-size: 12px;
        }
    </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">腾飞健康</div>
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item layui-this"><a href="">放射类检查</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a href="javascript:;" name="goBackIndex">返回首页</a></li>
        </ul>
    </div>
    <div style="float:left; width: 27%; height: 500px;border-top: #dddddd solid 2px; border-bottom: #dddddd solid 2px">
        <div style="width: 100%; height: 50px; margin-bottom: 5px; border-bottom: #dddddd solid 2px">
            <div class="layui-row">
                <div class="layui-input-inline layui-col-sm8" style="padding-top: 5px;padding-left: 8%; width: 60%;">
                    <input class="layui-input " placeholder="体检编号..." autocomplete="off" name="searchBookRegisteInput"
                           id="searchBookRegisteInput" maxlength="18" lay-verify="number">
                </div>
                <div class="layui-input-inline layui-col-sm2" style="padding-top: 5px;">
                    <button class="layui-btn" lay-filter="search" id="search">查询</button>
                </div>
                <div class="layui-input-inline layui-col-sm2" style="padding-top: 5px;">
                    <button class="layui-btn layui-btn-primary" lay-filter="clear" id="clear">清空</button>
                </div>
            </div>

        </div>

        <form class="layui-form layui-form-pane">
            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="userName" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="text" name="sex" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-block">
                    <input type="text" name="age" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">婚姻状态</label>
                <div class="layui-input-block">
                    <input type="text" name="maritalStatus" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">身份证号</label>
                <div class="layui-input-block">
                    <input type="text" name="userIdentity" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">挂号员</label>
                <div class="layui-input-block">
                    <input type="text" name="examinerName" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <div class="layui-form-item" style="height: 25px">
                <label class="layui-form-label">挂号日期</label>
                <div class="layui-input-block">
                    <input type="text" name="bookDate" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>
        </form>
    </div>

    <div style="float:left; width: 35%;height: 500px; border: #dddddd solid 2px; overflow-y:auto">
        <table class="layui-hide" id="itemList" lay-filter="itemList"></table>
    </div>

    <div style="float: right; width: calc(100% - 4px - 62%); height: 500px;border-top: #dddddd solid 2px; border-bottom: #dddddd solid 2px; overflow-y:auto">
        <div style="width: 100%; height: 10%; border-bottom: #dddddd solid 2px; text-align: center; line-height: 250%">
            <span id="examineItemName" style="font-size: 20px">无项目</span>
        </div>

        <div style="width: 100%; height: calc(100% - 30% - 10% - 2px);">
            <form class="layui-form layui-form-pane" lay-filter="submitValue">
                <input type="hidden" name="fillRadItemId" value="">

                <div class="layui-form-item layui-form-text" style="padding-left: 10px; padding-right: 10px; padding-top: 10px">
                    <label class="layui-form-label">检查所见：</label>
                    <div class="layui-input-block">
                            <textarea name="examineFind" placeholder="请输入内容" class="layui-textarea" style="position: relative"
                                      maxlength="500"
                                      onpropertychange="if(value.length>500) value=value.substr(0,500)"
                                      oninput="wordLeg(this);" lay-verify="required" disabled></textarea>
                        <div class="word">
                            <span class="text_count" name="examineFind">0</span> / <span class="num_count" id="numCount1">500</span>
                        </div>
                        <div style="margin-top: 20px"></div>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text" style="padding-right: 10px; padding-left: 10px; padding-top: 10px">
                    <label class="layui-form-label">诊断结果：</label>
                    <div class="layui-input-block">
                            <textarea name="diagnosis" placeholder="请输入内容" class="layui-textarea" style="position: relative"
                                      maxlength="500"
                                      onpropertychange="if(value.length>500) value=value.substr(0,500)"
                                      oninput="wordLeg(this);" lay-verify="required" disabled></textarea>
                        <div class="word">
                            <span class="text_count" name="diagnosis">0</span> / <span class="num_count" id="numCount2">500</span>
                        </div>
                        <div style="margin-top: 20px"></div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block" style="padding-left: 10%;padding-top: 15px">
                        <button type="submit" name="submit" class="layui-btn layui-btn-disabled" lay-submit=""
                                lay-filter="submitExamineValue">立即提交
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>

<script type="text/javascript" src="lib/layui/layui.js"></script>
<script>
    layui.use(['jquery', 'table', 'form'], function () {
        let $ = layui.jquery;
        let table = layui.table;
        let form = layui.form;

        let itemTable = table.render({
            elem: "#itemList",
            id: "itemListTableId",
            url: "/getExamineItemTableMsg",
            page: false,
            toolbar: false,
            size: "sm",
            method: "post",
            request: {
                pageName: "currentPageNum",
                limitName: "pageSize"
            },
            response: {
                countName: "totalCount",
                dataName: "data",
                msgName: "msg"
            },
            where: {
                searchBookRegisteInput: -1,
                examineType: "rad"
            },
            cols: [
                [
                    {field: "fillItemId", hide: true},
                    {field: "examineItemId", hide: true},
                    {field: "id", title: "id", hide: true},
                    {field: "itemName", title: "项目名称", width: 100, align: "center"},
                    {field: "examineArea", title: "检查部位", width: 100, align: "center"},
                    {field: "examineMethod", title: "检查方法", width: 100, align: "center"},
                    {field: "filledStatus", title: "检查状态", width: 100, align: "center", templet: "#filledStatusTple"},
                    {title: "操作", align: "center", templet: "#operationTple"}
                ]
            ],
            done: function (res, curr, count) {
                console.info(res, curr, count);
            }
        });

        $("#clear").on("click", function () {
            $("#searchBookRegisteInput").val("");
            $("input[name=userName]").val("");
            $("input[name=userIdentity]").val("");
            $("input[name=maritalStatus]").val("");
            $("input[name=sex]").val("");
            $("input[name=age]").val("");
            $("input[name=examinerName]").val("");
            $("input[name=bookDate]").val("");
            $("textarea[name=examineFind]").val("");
            $("textarea[name=examineFind]").attr("disabled", "disabled");
            $("textarea[name=diagnosis]").val("");
            $("textarea[name=diagnosis]").attr("disabled", "disabled");
            $("input[name=fillRadItemId]").val("");
            $("button[name=submit]").addClass("layui-btn-disabled");
            $("#examineItemName").html("无项目");
            form.render();
            table.reload("itemListTableId", {
                where: {
                    searchBookRegisteInput: -1,
                    examineType: "rad"
                },
                url: "/getExamineItemTableMsg",
                method: "get",
            });
        });

        $("#search").on("click", function () {
            let searchBookRegisteInput = $("#searchBookRegisteInput").val();
            $("#examineItemName").html("无项目");
            $("textarea[name=examineFind]").val("");
            $("textarea[name=diagnosis]").val("");
            $("textarea[name=examineFind]").attr("disabled", "disabled");
            $("textarea[name=diagnosis]").attr("disabled", "disabled");
            $("input[name=fillRadItemId]").val("");
            $("button[name=submit]").addClass("layui-btn-disabled");
            form.render();

            var reg = /^(0|[1-9][0-9]*)$/;
            if (reg.test(searchBookRegisteInput)) {
                table.reload("itemListTableId", {
                    where: {
                        searchBookRegisteInput: searchBookRegisteInput,
                        examineType: "rad"
                    },
                    url: "/getExamineItemTableMsg",
                    method: "get",
                });
                $.ajax({
                    url: "/getRegisteUserMsg",
                    dataType: "json",
                    data: "id=" + searchBookRegisteInput,
                    type: "post",
                    async: true,
                    success: function (responseData) {
                        if (responseData['code'] == 0) {
                            layer.msg("未找到预约或者挂号记录！", {
                                icon: 2,
                                time: 1500
                            });
                            $("input[name=userName]").val("");
                            $("input[name=userIdentity]").val("");
                            $("input[name=maritalStatus]").val("");
                            $("input[name=sex]").val("");
                            $("input[name=age]").val("");
                            $("input[name=examinerName]").val("");
                            $("input[name=bookDate]").val("");
                        }

                        $("input[name=userName]").val(responseData['user'].userName);
                        $("input[name=userIdentity]").val(responseData['user'].userIdentity);
                        if (responseData['user'].maritalStatus) {
                            $("input[name=maritalStatus]").val("未婚");
                        } else {
                            $("input[name=maritalStatus]").val("已婚");
                        }
                        if ((responseData['user'].userIdentity.substring(16, 17)) % 2 != 0) {
                            $("input[name=sex]").val("男");
                        } else {
                            $("input[name=sex]").val("女");
                        }
                        $("input[name=age]").val((new Date().getFullYear()) - (responseData['user'].userIdentity.substring(6, 10)));
                        $("input[name=examinerName]").val(responseData['examiner'].examinerName);
                        $("input[name=bookDate]").val(responseData['bookRegiste'].bookDate);
                    },
                    error: function () {
                        console.log("获取挂号信息请求失败！");
                        layer.msg("服务器错误！", {
                            icon: 2,
                            time: 1500
                        });
                    }
                });
            } else {
                layer.msg("输入错误！", {
                    icon: 2,
                    time: 1500
                });
                $("input[name=userName]").val("");
                $("input[name=userIdentity]").val("");
                $("input[name=maritalStatus]").val("");
                $("input[name=sex]").val("");
                $("input[name=age]").val("");
                $("input[name=examinerName]").val("");
                $("input[name=bookDate]").val("");
                $("button[name=submit]").addClass("layui-btn-disabled");

                form.render();
                table.reload("itemListTableId", {
                    where: {
                        searchBookRegisteInput: -1,
                        examineType: "rad"
                    },
                    url: "/getExamineItemTableMsg",
                    method: "get",
                });
            }
        });

        table.on("tool(itemList)", function (obj) {
            console.log(obj.data);
            $("button[name=submit]").removeClass("layui-btn-disabled");
            $("#examineItemName").html(obj.data.itemName + "-" + obj.data.examineArea + "-" + obj.data.examineMethod);
            $("input[name=fillRadItemId]").val(obj.data.fillItemId);
            $("textarea[name=examineFind]").val("");
            $("textarea[name=examineFind]").removeAttr("disabled");
            $("textarea[name=diagnosis]").val("");
            $("textarea[name=diagnosis]").removeAttr("disabled");
            form.render();
        });

        form.on("submit(submitExamineValue)", function (data) {
            console.log(data.field);
            $.ajax({
                url: "/submitRadClauseValue",
                dataType: "json",
                data: data.field,
                type: "post",
                async: true,
                success: function (responseResult) {
                    if (responseResult.code == 1) {
                        layer.msg("检查结果写入成功！", {
                            icon: 1,
                            time: 1500,
                        });
                    } else {
                        layer.msg("检查结果写入失败！", {
                            icon: 2,
                            time: 1500,
                        });
                    }
                    table.reload("itemListTableId", {
                        where: {
                            searchBookRegisteInput: $("#searchBookRegisteInput").val(),
                            examineType: "rad"
                        },
                        url: "/getExamineItemTableMsg",
                        method: "get",
                    });
                },
                error: function () {
                    layer.msg("服务器错误！", {
                        icon: 2,
                        time: 1500,
                    });
                }
            });
            return false;
        });

        //返回首页index.html
        $("a[name=goBackIndex]").on("click", function () {
            window.open("/unitIndex", "_top");
        });

        //备注输入框字数显示
        window.wordLeg = function (obj) {
            var currleg = $(obj).val().length;
            var length = $(obj).attr('maxlength');
            if (currleg >= length) {
                layer.msg('字数请在' + length + '字以内');
            } else {
                $('span[name='+obj.name+']').text(currleg);
            }
        }
    });
</script>
<script type="text/html" id="operationTple">
    <div class="layui-btn-container">
        {{# if(!d.filledStatus){ }}
        <span class="layui-btn layui-btn-default layui-btn-xs" lay-event="examine"
              style="padding-right: 5px;margin-right: 5px">检查</span>
        {{# } }}
        {{# if(d.filledStatus){ }}
        <span class="layui-btn layui-btn-default layui-btn-xs layui-btn-disabled" disabled="disabled"
              style="padding-right: 5px;margin-right: 5px">检查</span>
        {{# } }}
    </div>
</script>
<script type="text/html" id="filledStatusTple">
    {{# if(!d.filledStatus){ }}
    <span style="color: red">未检查</span>
    {{# } }}
    {{#　if(d.filledStatus){ }}
    <span style="color: green">已检查</span>
    {{# } }}
</script>
</body>
</html>